<%@ Language=VBScript %>
<%	
	set Conn=server.CreateObject("ADODB.Connection")
	Conn.Open Application("StrConn")
	nodemax=cint(Request("max"))
	nodeid=giaima(Request("id"))
	'nodeid=Request("id")
	IDFlow=request("IDFlow")
	on Error Resume next
	Conn.BeginTrans
	
	sql1="delete from TvFlowNode where Maworkflownode like '" & nodeid & "%'"
	conn.Execute sql1
		
	dim n,i,m,tempid
	n=cint(right(nodeid,2))
	Filename=request("Filename")	
	if nodemax>n then		
		for i=n+1 to nodemax
			'UPDATE FlowNode SET ID = "000013%" WHERE (((FlowNode.ID) Like "000013*"));
			if i<10 then
				id1=left(nodeid,len(nodeid)-2) & "0" & i
			else
				id1=left(nodeid,len(nodeid)-2)&i
			end if
			if i<11 then
				id2=left(nodeid,len(nodeid)-2) & "0" & (i-1)
			else
				id2=left(nodeid,len(nodeid)-2) & (i-1)
			end if			
			sql1="select Maworkflownode from tvflownode where Maworkflownode like '" & id1 & "%'"
			set rec=server.CreateObject("ADODB.Recordset")
			rec.Open sql1,conn,3
			Do while not rec.EOF
				id0=rec.Fields(0)
				sql1="update tvflownode set Maworkflownode='" & id2 & right(id0,len(id0)-len(id2))&"' where Maworkflownode='" & id0 & "'"
				Conn.Execute sql1
				rec.MoveNext
			loop
		next
	end if			
	if Err.number then
		Conn.RollbackTrans
	else
		Conn.CommitTrans
	end if
	conn.Close
	set conn=nothing
		lnk="../frmTvflowNodecd.asp?IDFlow="& IDFlow
	Response.Redirect(lnk)
%>
<script language=vbscript runat=server>
		Function GiaiMa(msText) 
	    Dim nC
	    Dim nD
	    Dim nE
	    Dim lA
	    Dim lB
	    Dim lI
	    Dim lJ
	    Dim lK
	    Dim sB
	    lA = Len(msText)
	    lB = lA - 1 - (lA - 1) \ 4
	    sB = Space(lB)
	    For lI = 1 To lB
	        lJ = lJ + 1
	        nC = Asc(Mid(msText, lJ, 1)) - 59	        
	        Select Case lI Mod 3
	        Case 1
	            lK = lK + 4
	            If lK > lA Then lK = lA
	            nE = Asc(Mid(msText, lK, 1)) - 59
	            nD = ((nE \ 16) And 3) * 64
	        Case 2
	            nD = ((nE \ 4) And 3) * 64
	        Case 0
	            nD = (nE And 3) * 64
	            lJ = lJ + 1
	        End Select
	        sB=Mid(sB,1,lI-1) & Chr(nC Or nD) & Mid(sB,lI+1,len(sB)-lI)
	    Next
	    GiaiMa = sB
	End Function
</script>
